@extends('admin.common.base-master')

@section('html-head')

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.bannerList')}}">banner设置</a>
        </div>

        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.bannerSet")}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>图片</th>
                    <th>标题</th>
                    <th>链接</th>
                    <th>分类</th>
                    <th>排序</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($banners) > 0)
                    @foreach($banners as $banner)
                        <tr id="banner_{{$banner->id}}">
                            <td>{{$banner->id}}</td>
                            <td class="account-td" style="width: 5%;">
                        <span class="photo" style="border-radius: 100%;display:initial">
                            @if($banner->img_id !== 0)
                                <a href="javascript:void(0);" class="openimg" data-key="{{$banner->img_id}}"><img src="{{\App\Http\Services\FileManager::getAliOssFile($banner->img_id)}}" alt=""></a>
                            @else
                                <img src="{{url('images/default-avatar.png')}}" alt="">
                            @endif
                        </span>
                            </td>
                            <td>{{$banner->title}}</td>
                            <td>{{$banner->link_url}}</td>
                            <td>{{$banner->classify}}</td>
                            <td>{{$banner->sort}}</td>
                            <td><a class="color2" href="{{route("Admin.Home.bannerSet")}}?id={{$banner->id}}">编辑</a> <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$banner->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
    </div>
    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");
                $.ajax({
                    url:'{{route("Api.Admin.sys.delBanner")}}',
                    type:'post',
                    dataType:'json',
                    data:{id:id},
                    success:function(obj){
                        if(obj.level == "success"){
                            $("#banner_"+id).hide('slow');
                        }else{
                            noty({type:obj.level,text:obj.message,timeout:600});
                        }
                    },
                    error:function(obj){
                        console.log(obj);
                    }

                });
            });
        });
    </script>
@endsection